#include "logger.hpp"
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/pattern_formatter.h> // Include the pattern formatter header

// Static member variable to store the logger
std::shared_ptr<spdlog::logger> Logger::logger_;

// Initialize the logger
void Logger::init() {
    // Create a console color sink
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    console_sink->set_level(spdlog::level::trace);

    // Set the log format
    auto formatter = std::make_unique<spdlog::pattern_formatter>();
    formatter->set_pattern("%Y-%m-%d %H:%M:%S.%e [%l] %v");
    console_sink->set_formatter(std::move(formatter));

    // Create the logger
    logger_ = std::make_shared<spdlog::logger>("console", console_sink);
    logger_->set_level(spdlog::level::trace);

    // Register the logger
    spdlog::register_logger(logger_);
}

// Get the logger
std::shared_ptr<spdlog::logger> Logger::get_logger() {
    return logger_;
}
